package SqlScript;

import java.util.UUID;

import org.hibernate.classic.Session;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.leo.dao.Dao;
import com.leo.entity.Admin;
import com.leo.entity.User;
import com.leo.util.HibernateSessionUtil;

public class Main {
	public static void main(String[] args) {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		Dao dao = (Dao) ctx.getBean("dao");
		Session session = HibernateSessionUtil.getInstance().getCurrentSession();
		session.beginTransaction();
		for (int i = 1; i < 100; i++) {
			User user = new User();
			user.setOid(UUID.randomUUID().toString());
			user.setAppURL("www.zhbit.com");
			user.setUsername(String.format("user%03d", i));
			user.setPassword(String.format("user%03d", i));
			user.setQueryRight(i%3 == 0 ? "yes" : "no");
			dao.save(user);
		}
		for (int i = 0; i < 10; i++) {
			Admin user = new Admin();
			user.setOid(UUID.randomUUID().toString());
			user.setUsername(String.format("admin%02d", i));
			user.setPassword(String.format("admin%02d", i));
			dao.save(user);
		}
		{
			User user = new User();
			user.setOid(UUID.randomUUID().toString());
			user.setAppURL("localhost");
			user.setUsername("user000");
			user.setPassword("user000");
			user.setQueryRight("yes");
			dao.save(user);
		}
		{
			Admin user = new Admin();
			user.setOid(UUID.randomUUID().toString());
			user.setUsername("admin");
			user.setPassword("admin");
			dao.save(user);
		}
		session.getTransaction().commit();
	}
}
